package ui.panel {

	import flash.display.Bitmap;
	
	import globals.Global;
	
	import ui.component.Grid;
	import ui.component.Page;
	import ui.component.TextButton;
	import ui.panel.equips.WarriorEquipInfo;
	
	import util.UIUtil;
	
	public class EquipPanel extends BasePanel {
		
		private var warriorEquipInfo:WarriorEquipInfo;
		private var gridList:Array;
		private var tabList:Array;
		private var page:Page;

		public function EquipPanel() {
			super();
			pid = PanelType.EQUIP_PANEL;
			updateTitle("武将装备");
		}
		
		override protected function initUI():void {
			super.initUI();
			warriorEquipInfo = new WarriorEquipInfo();
			warriorEquipInfo.x = 32;
			warriorEquipInfo.y = 80;
			addChild(warriorEquipInfo);
			
			tabList = new Array();
			var tab:TextButton;
			tab = UIUtil.getTextButton("武器", ["tab_on", "tab_on", "tab_on"], tabHandler);
			tab.id = 1;
			tab.x = 200;
			tab.y = 44;
			tab.enable = false;
			tab.getLabel().y = 12;
			tabList.push(tab);
			addChild(tab);
			
			tab = UIUtil.getTextButton("饰品", ["tab_off", "tab_off", "tab_off"], tabHandler);
			tab.id = 1;
			tab.x = 280;
			tab.y = 44;
			tab.enable = false;
			tab.getLabel().y = 12;
			tabList.push(tab);
			addChild(tab);
			
			tab = UIUtil.getTextButton("道具", ["tab_off", "tab_off", "tab_off"], tabHandler);
			tab.id = 1;
			tab.x = 360;
			tab.y = 44;
			tab.enable = false;
			tab.getLabel().y = 12;
			tabList.push(tab);
			addChild(tab);
			
			var bg:Bitmap = new Bitmap(Global.assetsManager.getAssetsAsBitmapData("grid_bg", "ui"));
			bg.x = 190;
			bg.y = 74;
			addChild(bg);
			
			var i:int;
			var grid:Grid;
			gridList = new Array();
			var gap:uint = Grid.SIZE + 16;
			for (i = 0; i<12; i++) {
				if (i < 2) {
					grid = new Grid("2001");
				} else {
					grid = new Grid();
				}
				grid.bag = PanelType.TOWER_PANEL;
				grid.index = i;
				grid.handler = gridHandler;
				grid.x = i % 4 * gap + 232;
				grid.y = int(i / 4) * gap + 110;
				addChild(grid);
				gridList.push(grid);
			}
			
			page = new Page(pageHandler);
			page.update(1);
			page.x = 380;
			page.y = 360;
			addChild(page);
		}
		
		private function tabHandler(button:TextButton):void {
			var id:uint = button.id;
			var tab:TextButton;
			for (var i:int = 0; i<tabList.length; i++) {
				tab = tabList[i];
				if (tab == button) {
					tab.setIcon(Global.assetsManager.getAssetsAsBitmapData("tab_on"));
					tab.getLabel().y = 10;
				} else {
					tab.setIcon(Global.assetsManager.getAssetsAsBitmapData("tab_off"));
					tab.getLabel().y = 12;
				}
			}
		}
		
		private function pageHandler(num:uint):void {
			trace(num);
		}
		
		private function gridHandler(bag:uint, index:uint):void {
			
		}
	}
}